package ch4

func Sum(numbers []int) (res int) {
	for _, number := range numbers {
		res += number
	}
	return res
}

func SumAll(numbersToSum ...[]int) (sums []int) {
	sums = make([]int, 0, len(numbersToSum))
	for _, numbers := range numbersToSum {
		sums = append(sums, Sum(numbers))
	}
	return
}

func SumTail(numbersToSum ...[]int) (sums []int) {
	sums = make([]int, 0, len(numbersToSum))
	for _, numbers := range numbersToSum {
		result := 0
		if len(numbers) != 0 {
			result = Sum(numbers[1:])
		}
		sums = append(sums, result)
	}
	return
}
